function t(){return ;}
function m(){return ;}
function n(){return document.getElementById('notes');}

function setVisibility(wV, tV, mV, nV, rV){
  document.getElementById('notice').style.visibility = (wV) ? "visible" : "hidden";
  document.getElementById('timer').style.visibility = (tV) ? "visible" : "hidden";
  document.getElementById('msg').style.visibility = (mV) ? "visible" : "hidden";
  document.getElementById('notes').style.visibility = (nV) ? "visible" : "hidden";
  document.getElementById('recipes').style.visibility = (rV) ? "visible" : "hidden";
}

function initEventHandlers(){
  
  var red = document.getElementById('reddotid');
  red.addEventListener("touchend", seeAnswer, false);
  red.addEventListener("click", seeAnswer, false);

  var blu = document.getElementById('bluedotid');
  blu.addEventListener("touchend", seeDetails, false);
  blu.addEventListener("click", seeDetails, false);

  var g1 = document.getElementById('greendot1');
  g1.addEventListener("touchend", showClock, false);
  g1.addEventListener("click", showClock, false);

  var g2 = document.getElementById('greendot2');
  g2.addEventListener("touchend", showClock, false);
  g2.addEventListener("click", showClock, false);   

  var g3 = document.getElementById('greendot3');
  g3.addEventListener("touchend", showClock, false);
  g3.addEventListener("click", showClock, false);   

  var rec = document.getElementById('explore');
  rec.addEventListener("touchend", showRecipe, false);
  rec.addEventListener("click", showRecipe, false);   
}

//via http://stackoverflow.com/questions/5284878/how-do-i-correctly-detect-orientation-change-using-javascript-and-phonegap-in-io
function orientationCheck(){
    switch(window.orientation) 
    {  
      case -90:
      case 90:
        setVisibility(false, true, false, false, false);
        break; 
      default:
        setVisibility(true, false, false, false, false);
        break; 
    }
  }

  window.onorientationchange = function()
  {
    orientationCheck();
  };

//via https://gist.github.com/1563963
(function() {
 
  function DateDiff(date1, date2) {
    this.days = null;
    this.hours = null;
    this.minutes = null;
    this.seconds = null;
    this.date1 = date1;
    this.date2 = date2;
 
    this.init();
  }
 
  DateDiff.prototype.init = function() {
    var data = new DateMeasure(this.date1 - this.date2);
    this.days = data.days;
    this.hours = data.hours;
    this.minutes = data.minutes;
    this.seconds = data.seconds;
  };
 
  function DateMeasure(ms) {
    var d, h, m, s;
    s = Math.floor(ms / 1000);
    m = Math.floor(s / 60);
    s = s % 60;
    h = Math.floor(m / 60);
    m = m % 60;
    d = Math.floor(h / 24);
    h = h % 24;
    
    this.days = d;
    this.hours = h;
    this.minutes = m;
    this.seconds = s;
  };
 
  Date.diff = function(date1, date2) {
    return new DateDiff(date1, date2);
  };
 
  Date.prototype.diff = function(date2) {
    return new DateDiff(this, date2);
  };
 
})()


var clock = {
   
  digits : ["zero", "one", "two", "three", "foure", "five", "six", "seven", "eight", "nine"],
  
  init : function(){
    //var $digit = $('.digit');
    
    // Ugly....
    this.day = [document.getElementById('d1'), document.getElementById('d2')]; 
    this.hour = [document.getElementById('h1'), document.getElementById('h2')];    
    this.min  = [document.getElementById('m1'), document.getElementById('m2')];    
    this.sec  = [document.getElementById('s1'), document.getElementById('s2')];
    
    

    var time = this.getCountDownArray();
    this.drawDay(time);
    this.drawHour(time);
    this.drawMinute(time);
    this.drawSecond(time);    
    this.drawInterval(this.drawSecond, function(time){
      return 1000;
    })
    
     
  },
  
  dDay : new Date(2012, 11, 21, 12, 21, 12, 000),

  getCountDownArray : function(){
    var now = new Date();
    var diff = new Date.diff(this.dDay,now);    
    return [diff.days, diff.hours, diff.minutes, diff.seconds];
  },
    
  drawInterval : function(func, timeCallback){
    var time = this.getCountDownArray();
    
    func.call(this, time);    
    
    var that = this;
    setTimeout(function(){
        that.drawInterval(func, timeCallback);      
    }, timeCallback(time));
  },

  drawDay : function(time){
    this.drawDigits(this.day, time[0]);  
  },

  drawHour : function(time){
    this.drawDigits(this.hour, time[1]);
    if (time[1] == 24){
        this.drawDay(this.getCountDownArray());
    } 
  },
  
  drawMinute : function(time){
    this.drawDigits(this.min,  time[2]);
    if (time[2] == 59){
        this.drawHour(this.getCountDownArray());
    }  
  },
  
  drawSecond : function(time){  
    this.drawDigits(this.sec,  time[3]);
    if (time[3] == 59){
        this.drawMinute(this.getCountDownArray());
    }
  },
  
  drawDigits : function(digits, digit){
    var ten = Math.floor(digit / 10);
    var one = Math.floor(digit % 10);

    digits[0].setAttribute('class', 'digit '+this.digits[ten]);
    digits[1].setAttribute('class', 'digit '+this.digits[one]);
  }
    
}; 
    
function seeAnswer(){
  setVisibility(false, false, true, false, false);
}

function seeDetails(){
  setVisibility(false, false, false, true, false);
}

function showClock(){
  setVisibility(false, true, false, false, false);
}

function showRecipe(){
  setVisibility(false, false, false, false, true);
}